<?php
class LoginController extends Zend_Controller_Action
{
    public function indexAction()
    {
        // generate a login form
        $form = new Application_Form_Login();
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()->getPost())) {
                // get credentials from user input
                // initialize authentication adapter
                // perform authentication and test result
                $values = $form->getValues();
                $db = Zend_Db_Table_Abstract::getDefaultAdapter();
                $adapter = new Zend_Auth_Adapter_DbTable($db);
                $adapter->setTableName('user')
                	    ->setIdentityColumn('username')
                	    ->setCredentialColumn('password');
                	 
                $adapter->setIdentity($values['username'])
                	    ->setCredential($values['password']);
                $auth = Zend_Auth::getInstance();
                $result = $auth->authenticate($adapter);
                if ($result->isValid()) {
                    $this->_helper->getHelper('FlashMessenger')->addMessage(
                    'You were successfully logged in.');
                    //$this->_redirect('/admin/index');
                    echo 'Success';
					echo $result->getIdentity() . "\n\n";
					print_r($adapter->getResultRowObject());
                } else {
                	echo 'Failed';
                    $this->view->message = 'You could not be logged in. Please try again.';
                }
            }
        }
    }
}







